import { useUser } from '@/store/modules/user';
const userStore = useUser();
interface EnumItem {
  label: string;
  value: string | number;
  color: string;
}
export const enumsData: any = {
  gender: {
    1: { label: '男', value: 1 },
    2: { label: '女', value: 2 },
    3: { label: '保密', value: 3 },
  },
  fileCategory: {
    'COMMON': { label: 'COMMON', value: 'COMMON' },
    'COURSE_EXERCISE_BACKUP': { label: '课堂练习备份', value: 'COURSE_EXERCISE_BACKUP' },
    'HANDWRITING': { label: '学生笔迹信息', value: 'HANDWRITING' },
    'APP_VERSION': { label: 'APP版本信息', value: 'APP_VERSION' },
    'EXCEL_ERROR': { label: '导入失败文件', value: 'EXCEL_ERROR' },
  },
};
function getEnumData(name) {
  const asyncData = userStore.getEnumData[name];
  const data: any = {};
  asyncData?.forEach((item) => {
    data[item.id] = {
      label: item.name,
      value: item.id,
      color: '',
    };
  });
  const map: any = asyncData ? data : enumsData[name];
  return map;
}
export function getEnumsMap(name: string) {
  const map = getEnumData(name);
  return map[name];
}
export function getEnumsArray(name: string) {
  const data: EnumItem[] = [];
  const map = getEnumData(name);
  for (const key in map) {
    data.push(map[key]);
  }
  return data;
}
export function getEnumDataLabel(name: string, key: number | string) {
  const map = getEnumData(name);
  return map[key]?.label ?? '未知';
}
export const getAsyncEnums = (name: string) => {
  const enumData = userStore.getEnumData;
  const map: any = {};
  const array = enumData[name]
    ? enumData[name].map((item) => {
        const temp = {
          label: item.value,
          value: item.code,
          color: item.backupValue,
        };
        map[item.code] = temp;
        return temp;
      })
    : [];
  return {
    map: map,
    array: array,
  };
};
